<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourArticle;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FourArticleController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FourArticle(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title','标题');
            $grid->column('pic','缩略图')->image([],80,80);
            $grid->column('author','作者');
            $grid->column('content','内容');
            $grid->column('created_at','操作时间');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            // 设置表单提示值
            $grid->quickSearch('title')->placeholder('搜索...');
            // 开启字段选择器功能
            $grid->showColumnSelector();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourArticle(), function (Show $show) {
            $show->field('id');
            $show->field('title','标题');
            $show->field('pic','缩略图');
            $show->field('author','作者');
            $show->field('content','文章内容');
            $show->field('article_status');
            $show->field('cate_id');
            $show->field('created_at','上传时间');

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FourArticle(), function (Form $form) {
            $form->display('id');
            $form->text('title','标题');
            $form->image('pic','缩略图')->thumbnail('mini_pic','80','80');
            $form->text('author','作者');
            $form->editor('content','文章内容');
            // 添加开关操作
            $form->switch('article_status', '文章状态');
//            $form->text('cate_id');
            $form->display('created_at','上传时间');

        });
    }
}
